﻿using Microsoft.EntityFrameworkCore;
using mozhi.smarterp.BasicData.Currencies;
using mozhi.smarterp.BasicData.Customers;
using mozhi.smarterp.BasicData.DataLinkages;
using mozhi.smarterp.BasicData.Employees;
using mozhi.smarterp.BasicData.ExpenseItems;
using mozhi.smarterp.BasicData.NumberRules;
using mozhi.smarterp.BasicData.Organizations;
using mozhi.smarterp.BasicData.PaymentTerms;
using mozhi.smarterp.BasicData.Products;
using mozhi.smarterp.BasicData.TaxRates;
using mozhi.smarterp.BasicData.Units;
using mozhi.smarterp.BasicData.Warehouses;
using Volo.Abp;
using Volo.Abp.EntityFrameworkCore.Modeling;

namespace mozhi.smarterp.BasicData.EntityFrameworkCore;

public static class BasicDataDbContextModelCreatingExtensions
{
    public static void ConfigureBasicData(
        this ModelBuilder builder)
    {
        Check.NotNull(builder, nameof(builder));

        /* Configure all entities here. Example:

        builder.Entity<Question>(b =>
        {
            //Configure table & schema name
            b.ToTable(BasicDataDbProperties.DbTablePrefix + "Questions", BasicDataDbProperties.DbSchema);

            b.ConfigureByConvention();

            //Properties
            b.Property(q => q.Title).IsRequired().HasMaxLength(QuestionConsts.MaxTitleLength);

            //Relations
            b.HasMany(question => question.Tags).WithOne().HasForeignKey(qt => qt.QuestionId);

            //Indexes
            b.HasIndex(q => q.CreationTime);
        });
        */

        builder.Entity<Organization>(b =>
        {
            b.ToTable(BasicDataDbProperties.DbTablePrefix + "Organization", BasicDataDbProperties.DbSchema);
            b.ConfigureByConvention();
        });

        builder.Entity<Supplier>(b =>
        {
            b.ToTable(BasicDataDbProperties.DbTablePrefix + "Supplier", BasicDataDbProperties.DbSchema);
            b.ConfigureByConvention();
        });

        builder.Entity<SupplierContactItem>(b =>
        {
            b.ToTable(BasicDataDbProperties.DbTablePrefix + "SupplierContactItem", BasicDataDbProperties.DbSchema);
            b.ConfigureByConvention();
        });

        builder.Entity<Customer>(b =>
        {
            b.ToTable(BasicDataDbProperties.DbTablePrefix + "Customer", BasicDataDbProperties.DbSchema);
            b.ConfigureByConvention();
        });

        builder.Entity<CustomerContactItem>(b =>
        {
            b.ToTable(BasicDataDbProperties.DbTablePrefix + "CustomerContactItem", BasicDataDbProperties.DbSchema);
            b.ConfigureByConvention();
        });

        builder.Entity<Employee>(b =>
        {
            b.ToTable(BasicDataDbProperties.DbTablePrefix + "Employee", BasicDataDbProperties.DbSchema);
            b.ConfigureByConvention();
        });

        builder.Entity<Product>(b =>
        {
            b.ToTable(BasicDataDbProperties.DbTablePrefix + "Product", BasicDataDbProperties.DbSchema);
            b.ConfigureByConvention();
        });

        builder.Entity<Currency>(b =>
        {
            b.ToTable(BasicDataDbProperties.DbTablePrefix + "Currency", BasicDataDbProperties.DbSchema);
            b.ConfigureByConvention();
        });

        builder.Entity<ExchangeRate>(b =>
        {
            b.ToTable(BasicDataDbProperties.DbTablePrefix + "ExchangeRate", BasicDataDbProperties.DbSchema);
            b.ConfigureByConvention();
        });

        builder.Entity<Unit>(b =>
        {
            b.ToTable(BasicDataDbProperties.DbTablePrefix + "Unit", BasicDataDbProperties.DbSchema);
            b.ConfigureByConvention();
        });

        builder.Entity<TaxRate>(b =>
        {
            b.ToTable(BasicDataDbProperties.DbTablePrefix + "TaxRate", BasicDataDbProperties.DbSchema);
            b.ConfigureByConvention();
        });

        builder.Entity<ProductAuxiliaryUnit>(b =>
        {
            b.ToTable(BasicDataDbProperties.DbTablePrefix + "ProductAuxiliaryUnit", BasicDataDbProperties.DbSchema);
            b.ConfigureByConvention();
        });

        builder.Entity<DocumentNumberRule>(b =>
        {
            b.ToTable(BasicDataDbProperties.DbTablePrefix + "DocumentNumberRule", BasicDataDbProperties.DbSchema);
            b.ConfigureByConvention();
        });

        builder.Entity<Warehouse>(b =>
        {
            b.ToTable(BasicDataDbProperties.DbTablePrefix + "Warehouse", BasicDataDbProperties.DbSchema);
            b.ConfigureByConvention();
        });

        builder.Entity<Location>(b =>
        {
            b.ToTable(BasicDataDbProperties.DbTablePrefix + "Location", BasicDataDbProperties.DbSchema);
            b.ConfigureByConvention();
        });

        builder.Entity<ExpenseItem>(b =>
        {
            b.ToTable(BasicDataDbProperties.DbTablePrefix + "ExpenseItem", BasicDataDbProperties.DbSchema);
            b.ConfigureByConvention();
        });

        builder.Entity<PaymentTerm>(b =>
        {
            b.ToTable(BasicDataDbProperties.DbTablePrefix + "PaymentTerm", BasicDataDbProperties.DbSchema);
            b.ConfigureByConvention();
        });
    }
}
